﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BlogsManage
{
    public partial class frmRegister : Form
    {
        public frmRegister()
        {
            InitializeComponent();
        }

        private void frmRegister_Load(object sender, EventArgs e)
        {

        }

        //数据库帮助类
        DBhelp db = new DBhelp();
        //创建数据集
        DataSet ds = new DataSet();
       

        private void frmregister_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 注册按钮单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnregister_Click(object sender, EventArgs e)
        {
            if (Ck() == true)
            {




                if (this.txtu_password.Text == this.txtu_pass.Text)
                {
                    Rs();
                }
                else
                {
                    MessageBox.Show("两次密码不一致");
                    return;
                }
            }


        }
        public void Rs()
        {
            string sql = string.Format("INSERT INTO Users ( Username, Password) VALUES('{0}', '{1}')", this.txtu_name.Text, this.txtu_password.Text);
            int i = db.IDU(sql);
            if (i == 1)
            {
                MessageBox.Show("注册成功，确认后自动跳转到登录");
                frmLogin frm = new frmLogin();

                frm.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("注册失败");
                return;
            }
        }
        /// <summary>
        /// 非空
        /// </summary>
        public Boolean Ck()
        {
            if (this.txtu_name.Text == "")
            {
                MessageBox.Show("输入用户名");
                return false;
            }
            else if (this.txtu_password.Text == "")
            {
                MessageBox.Show("输入密码");
                return false;
            }
            else if (this.txtu_pass.Text == "")
            {
                MessageBox.Show("再次确认密码");
                return false;
            }
            else
            {
                return true;
            }




        }

        private void btnESc_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
